package com.qf.sy2103.springboot.Util;


import com.qf.sy2103.springboot.vo.Uservo;
import lombok.extern.slf4j.Slf4j;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.HandlerInterceptor;
import org.springframework.web.servlet.config.annotation.EnableWebMvc;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import java.util.Objects;

@Slf4j
//定义拦截器
public class Myintercept implements HandlerInterceptor {

    @Override
    public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws Exception {
        HttpSession session = request.getSession();

        Uservo user = (Uservo) session.getAttribute("user");

        if (Objects.isNull(user)){
            log.info("拦截到的路径是 {} 拦截 重定向" ,request.getContextPath());
            //没登录
            response.sendRedirect("/User/login.html");
            return false;
        }
//        request.getRequestDispatcher("/User/find.jsp").forward(request,response);
        //登陆过
        return true;
    }
}
